<?php

if ( isset($_POST['submit']) )
{
	$ftp_server = $_POST['server'];
	$ftp_user_name = $_POST['username'];
	$ftp_user_pass = $_POST['password'];
	$directory = $_POST['directory'];
	$destination_file = "wpinstaller.php";
	$source_file = "wpinstaller.php";

	// set up basic connection
	$conn_id = ftp_connect($ftp_server); 

	// login with username and password
	$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

	// check connection
	if ((!$conn_id) || (!$login_result)) { 
			echo "FTP connection has failed!";
			echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
			exit; 
		} else {
			echo "Connected to $ftp_server, for user $ftp_user_name <br>";
		}

	// try to change the directory to somedir
	if (@ftp_chdir($conn_id, "$directory")) {
		echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
	} else { 
		if (ftp_mkdir($conn_id, $directory)) {
			if (@ftp_chdir($conn_id, "$directory")) {
				echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
			} else { 
				echo "error thing";
			}
		} else {
			echo "There was an error creating the directory.";
		}
	}

	// upload the file
	if ( $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY) )
	{
		echo "Uploaded!";
	}
	else
	{
		echo "didn't upload";
	}

	// close the FTP stream 
	ftp_close($conn_id); 
}
?>

<form method="post" action="">
	<p>ftp address<br /><input type="text" name="server" /></p>
	<p>username<br /><input type="text" name="username" /></p>
	<p>password<br /><input type="password" name="password" /></p>
	<p>directory<br /><input type="text" name="directory" /></p>
	<p><input type="submit" name="submit" value="Submit" /></p>
</form>